package com.guigu.gulicommon.tools;

import com.guigu.gulicommon.constant.enumes.ThreadPoolWaitPolicy;

import java.util.concurrent.RejectedExecutionHandler;

/**
 * 线程池工具类
 *
 * @author 陈俊杰
 * @since 2024-8-9
 */
public class ThreadPoolTool {
    /**
     * 根据线程池等待策略码获取线程池等待策略
     * <p>
     * 如果策略码不存在，返回null,
     * 存在则返回对应等待策略
     *
     * @param threadPoolWaitPolicy 线程池等待策略枚举
     * @param policyCode           线程池等待策略码
     * @return RejectedExecutionHandler-线程池等待策略
     */
    public static RejectedExecutionHandler getThreadPoolWaitPolicyByCode
    (ThreadPoolWaitPolicy[] threadPoolWaitPolicy, Integer policyCode) {
        for (ThreadPoolWaitPolicy poolWaitPolicy : threadPoolWaitPolicy) {
            if (poolWaitPolicy.getPolicyCode().equals(policyCode)) {
                return poolWaitPolicy.getPolicy();
            }
        }
        return null;
    }


}
